<?php //issues
   require_once('../../../Connections/ocmanmanager.php');
   require_once('../../../Connections/checkuser.php');
     
    if(isset($_GET['id']) && $_GET['id'] > 0 ){
     $queryissue = "SELECT
    `issuetable`.`id`
    , `projects`.`projectname`
    , `issuetable`.`issuetitle`
    , `issuetable`.`issuedescription`
    , `issuetable`.`datecreated`
    , `issuetable`.`notes`
    , `issuesstatus`.`statustitle`
FROM
    `ocmanozc_manager`.`issuetable`
    INNER JOIN `ocmanozc_manager`.`projects` 
        ON (`issuetable`.`projectid` = `projects`.`id`)
    INNER JOIN `ocmanozc_manager`.`issuesstatus` 
        ON (`issuetable`.`issuestatusid` = `issuesstatus`.`id`)
WHERE (`issuetable`.`id` = ".$_GET['id'].")"; 
    
    
    $querynotes = "SELECT
    `issuetable`.`id`
    , `issuenotes`.`id`
    , `issuenotes`.`notetitle`
    , `issuenotes`.`notes`
    , `issuenotes`.`dateadded`
    , `issuenotes`.`addedby`
    , `issuenotes`.`important`
    , `issuenotes`.`deleted`
FROM
    `ocmanozc_manager`.`issuetable`
    INNER JOIN `ocmanozc_manager`.`issuenotes` 
        ON (`issuetable`.`id` = `issuenotes`.`issueid`)
WHERE (`issuetable`.`id` = ".$_GET['id'].")";    



mysql_select_db($database_ocmanmanager, $ocmanmanager);
    $issueresult = mysql_query($queryissue,$ocmanmanager);
    $row_issues = mysql_fetch_assoc($issueresult);
    
    $notesresult = mysql_query($querynotes,$ocmanmanager);
    $row_notes = mysql_fetch_assoc($notesresult);
    $row_count = mysql_num_rows($notesresult);
    
    //print json_encode($rows);
    $phpobj = json_encode($rows);
    
    mysql_close($ocmanmanager);
}
    //$link = mysql_connect('localhost', 'ocmanozc_user1', '+0Fg8.8S-?pc');
    /*
    if($_SERVER['HTTP_HOST']=="localhost") {
       $link = mysql_connect('localhost', 'root', '');
       
    } 
    else {
        $link = mysql_connect('localhost', 'ocmanozc_user1', '+0Fg8.8S-?pc');
    }
           
    if (!$link) {
        die('Could not connect: ' . mysql_error());
    } 
    */
   
    //$query = "select * from projects order by id asc";
    
    /*mysql_select_db($database_ocmanmanager,$ocmanmanager);
    $result = mysql_query($query);
    $rows = array();*/
    
    
?>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <title>Issues Form  </title>
        <!--link rel="stylesheet" type="text/css" href="http://code.jquery.com/mobile/latest/jquery.mobile.min.css" /-->
        <link type="text/css" href="css/ui-lightness/jquery-ui-1.8.22.custom.css" rel="stylesheet" />
        <link rel="stylesheet" type="text/css" href="jquery.mobile.fmtd.css" />
        <!--link rel="stylesheet" type="text/css" href="http://dev.jtsage.com/cdn/datebox/latest/jqm-datebox.min.css" /-->
        <link rel="stylesheet" type="text/css" href="jqm-datebox.fmtd.css" />  
        
        <link rel="stylesheet" href="issues.css" />
        
        <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script> 
        <script type="text/javascript" src="http://code.jquery.com/ui/1.8.22/jquery-ui.min.js"></script>
        <script type="text/javascript" src="http://code.jquery.com/mobile/latest/jquery.mobile.min.js"></script>
        <script type="text/javascript" src="http://dev.jtsage.com/cdn/datebox/latest/jqm-datebox.core.min.js"></script>
        <script type="text/javascript" src="http://dev.jtsage.com/cdn/datebox/latest/jqm-datebox.mode.calbox.min.js"></script>       
		<script type="text/javascript" src="http://dev.jtsage.com/cdn/datebox/i18n/jquery.mobile.datebox.i18n.en_US.utf8.js"></script>
        
        <script type="text/javascript" src="insert.js"> </script>

    </head>
    <body>
    <script type="text/javascript">
    
   // var obj = JSON.stringify('<?php echo $phpobj; ?>');
    //alert(obj);
    
	$(function() {
		$( ".datepicker" ).datepicker();
	});
	
    </script>
    
        <!-- Home -->
            <form id="issues" action="index.php" method="post">
                <div data-role="page" id="page1" style="position: relative;">
                <div data-role="content" id="logo">
    			<img src="../images/ozcretelogo.png" />			
                <div id="addr">
                    <strong>Ozcrete Pools Pty Ltd</strong><br />
                    ABN: 74984824030 <br />
                    BSA: 1100119<br />
                    Ph: 07 55466443<br />
                    Mob: 0418756170<br />
                    Email: info@ozcrete.com.au<br />
                    48 Conebush Circuit<br />
                    Ormeu  QLD 4820
    			</div><!-- #addr -->
                </div><!-- logo end -->
                
                <div data-role="content" style="padding: 15px">
                    <h2>
                        Issues Form
                    </h2>
                    
    
                    <div data-role="fieldcontain" class=" ui-body ui-br">
                        <label for="mydate" >Date</label>
                    	<input name="mydate" id="mydate" type="text" class="datepicker"  placeholder="Start Date"/><br /><br />
                        <label for="createdby" >Created By</label>
                    	<input name="createdby" id="createdby" type="text" placeholder="Created By"/>
                    </div>
                    <table width="99%" border="1" cellpadding="0" cellspacing="0" align="center">
                        <thead>
                        	<tr class="ui-widget-header ">
                        		<th scope="col" width="5%">ID</th>
                                <th scope="col" width="15%">Project</th>
                                <th scope="col" width="20%">Description </th >
                                <th scope="col" width="15%">Notes </th>
                                <th scope="col" width="10%">Status</th>
                                <th scope="col" width="10%">Last Updated</th>
                                <th scope="col" width="15%">Assigned To</th>
                            
        	                </tr>
                         </thead>
                         <?php 
                         
                         ?>
                         <tbody>
                            <tr >
                                <td><input name="ihid" id="ihid" value="<?php echo $row_issues['id']?>" /></td>
                                <td><input name="ihproj" id="ihproj" type="text" value="<?php echo $row_issues['projectname']?>"> 
                                    
                                </td>
                                <td><textarea name="ihdesc" id="ihdesc" ><?php echo $row_issues['issuedescription'];?></textarea> </td>
                                <td><textarea name="ihnotes" id="ihnotes" ><?php echo $row_issues['notes']?></textarea> </td>
                                <td><input name="ihstatus" id="ihstatus" type="text" value="<?php echo $row_issues['statustitle']?>"/></td>
                                <td><input name="ihupdate" id="ihupdate" type="text" class="datepicker" value="<?php $issueupdate;?>"/></td> <!-- data-role="datebox" data-options='{"mode": "calbox"}' -->
                                <td><!--input name="ihassign" id="ihassign" type="text" /-->
                                    <select name="ihassign" id="ihassign">
                                         <?php echo "<option value=''>".$assignto."</option>" ?>
                                    </select>
                                </td>
                            </tr>
                          </tbody>
                    </table>
                    <!-- jquerymobile table -->
    						
                    <table id="inotes" summary="This table list issues assigned to individuals" width="99%" style"font-size: 11px; font-family: 'Lucida Sans Unicode', 'Lucida Grande', sans-serif" border="1" cellpadding="0" cellspacing="0">
                      <caption>Issues Notes</caption>
                      <thead>
                            <tr class="ui-widget-header ">
                              <th scope="col" width="8%">Date:</th>  
                              <th scope="col" width="38%">Notes:</th>  
                              <th scope="col" width="21%">Next Action:</th>  
                              <th scope="col" width="15%">Assigned To:</th>  
                              <th scope="col" width="10%">To be done by:</th>  
                              <th scope="col" width="2%">Important</th>
                              <th scope="col" width="2%">Delete</th>
                            </tr>
                      </thead>
                      <tfoot>
                            <tr>
                              <td colspan="6"></td>
                            </tr>
                      </tfoot>
                      <tbody>
                     	<?php if($row_count<1){
                     	  echo "<tr><td colspan='7' border='1'>Nothing to display</td></tr>";
                          
                     	}
                         else {
                             do { ?>
                			  
                			   <tr>
                                 <td> <input  type="text" name="idate[]"  class="idate" size="4" value="<?php echo date("m/d/Y",$row_notes['dateadded']);?>"/></td>
                                 <td><textarea name="inotes" ><?php echo $row_notes['notetitle'];?></textarea></td>                     
                                 <td><input  type="text" name="iaction[]"  class="iaction"   size="4" /></td>
                                 <td><input  type="text" name="assign[]"  class="iassign"   size="4" /></td>
                                 <td><input  type="text" name="idoneby[ ]"  class="idoneby datepicker" size="4" /></td>
                                 <td><input type="checkbox" class="important" <?php echo ($row_notes['important']==1)? "checked":"";?>/></td>
                                 <td><input type="checkbox" class="deleted" /></td>
                              </tr>
                              <?php } while ($row_notes = mysql_fetch_assoc($notesresult)); 
                          }?>
                         
               
                      </tbody>
                    </table>
                    
                    <br />
     			<div style="float: right;margin-right: 10px;"><a href="index.html" data-role="button" data-icon="check" style="width: 100px;margin:0 auto;">Save</a></div>
                </div><!-- content -->
            
            </div><!-- page -->
        
        </form>
        
        <!-- modal form start -->
        
        <div id="dialog-form" title="Create new user" style="display: hidden;">
        	<p class="validateTips">All form fields are required.</p>
        
        	<form>
        	<fieldset>
                <input type="hidden" name="tdate" />
        		<label for="note">Name</label>
        		<input type="text" name="note" id="name" class="text ui-widget-content ui-corner-all" />
        		<label for="next-act">Next Action</label>
        		<textarea name="next-act" id="next-act" class="text ui-widget-content ui-corner-all" ></textarea>
        		<label for="assignto">Assign To:</label>
        		<input type="text" name="assignto" id="assignto" value="" class="text ui-widget-content ui-corner-all" />
                <label for="tobedoneby">To Be Done By:</label>
        		<input type="text" name="tobedoneby" id="tobedoneby" value="" class="text ui-widget-content ui-corner-all" />
                <label for="important">Important?</label>
        		<input type="text" name="important" id="important" value="" class="text ui-widget-content ui-corner-all" />
                                
        		
        	</fieldset>
        	</form>
        </div>
        
        <!-- modal form end -->
     <script>
	$(function() {
		// a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
		$( "#dialog:ui-dialog" ).dialog( "destroy" );
		
		var name = $( "#name" ),
			email = $( "#email" ),
			password = $( "#password" ),
			allFields = $( [] ).add( name ).add( email ).add( password ),
			tips = $( ".validateTips" );

		function updateTips( t ) {
			tips
				.text( t )
				.addClass( "ui-state-highlight" );
			setTimeout(function() {
				tips.removeClass( "ui-state-highlight", 1500 );
			}, 500 );
		}

		function checkLength( o, n, min, max ) {
			if ( o.val().length > max || o.val().length < min ) {
				o.addClass( "ui-state-error" );
				updateTips( "Length of " + n + " must be between " +
					min + " and " + max + "." );
				return false;
			} else {
				return true;
			}
		}

		function checkRegexp( o, regexp, n ) {
			if ( !( regexp.test( o.val() ) ) ) {
				o.addClass( "ui-state-error" );
				updateTips( n );
				return false;
			} else {
				return true;
			}
		}
		
		$( "#dialog-form" ).dialog({
			autoOpen: false,
			height: 300,
			width: 350,
			modal: true,
			buttons: {
				"Create an account": function() {
					var bValid = true;
					allFields.removeClass( "ui-state-error" );

					bValid = bValid && checkLength( name, "username", 3, 16 );
					bValid = bValid && checkLength( email, "email", 6, 80 );
					bValid = bValid && checkLength( password, "password", 5, 16 );

					bValid = bValid && checkRegexp( name, /^[a-z]([0-9a-z_])+$/i, "Username may consist of a-z, 0-9, underscores, begin with a letter." );
					// From jquery.validate.js (by joern), contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
					bValid = bValid && checkRegexp( email, /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i, "eg. ui@jquery.com" );
					bValid = bValid && checkRegexp( password, /^([0-9a-zA-Z])+$/, "Password field only allow : a-z 0-9" );

					if ( bValid ) {
						$( "#users tbody" ).append( "<tr>" +
							"<td>" + name.val() + "</td>" + 
							"<td>" + email.val() + "</td>" + 
							"<td>" + password.val() + "</td>" +
						"</tr>" ); 
						$( this ).dialog( "close" );
					}
				},
				Cancel: function() {
					$( this ).dialog( "close" );
				}
			},
			close: function() {
				allFields.val( "" ).removeClass( "ui-state-error" );
			}
		});

		$( "#create-user" )
			.button() 
			.click(function() {
				$( "#dialog-form" ).dialog( "open" );
			});
	});
	</script>   
    </body>
</html>